package spittr.confg;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * 对应 DispatcherServlet创建的应用上下文配置。
 * @author LBH
 *
 */
@Configuration
@EnableWebMvc
@ComponentScan("spittr.web")
public class WebConfig extends WebMvcConfigurerAdapter{
    @Bean
	public ViewResolver viewResolver(){
    	/*
    	 * 试图解析器
    	 */
		InternalResourceViewResolver resolver=new InternalResourceViewResolver();
		resolver.setPrefix("/WEB-INF/views/");
		resolver.setSuffix(".jsp");
		resolver.setExposeContextBeansAsAttributes(true);
		return resolver;
	}
    
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){
    	/*
    	 * 重载这个方法的目的，我们要求DispatcherServlet将对静态资源的请求转发到Servlet容器中默认的Servlet上
    	 * ，而不是使用DispatcherServlet本身来处理此类=请求。
    	 */
    	configurer.enable();
    }
}
